<?php
namespace app\admin\model;

use think\Db;
use think\Model;

class Common extends Model{
    protected $table;
    public function __construct($data = [])
    {
        parent::__construct($data);
    }
    /**添加数据
     * @param array $data
     * @return int|string
     */
    public function addData($data=array()){
        return Db::name($this->table)->insert($data);
    }
    /**更新数据
     * @param array $data 要更新的数据
     * @param array $where 更新条件
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function saveData($where=array(),$data=array()){
        return Db::name($this->table)->where($where)->update($data);
    }
    /**删除数据
     * @param array $where 删除条件
     * @return int
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function delData($where=array()){
        return Db::name($this->table)->where($where)->delete();
    }
    /**查询一条数据
     * @param array $where 查询条件
     * @param string $filed 查询字段列表
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getOne($where = array(), $filed = '*')
    {
        return Db::name($this->table)->where($where)->field($filed)->find();
    }
    public function getAll($where=array(),$filed='*'){
        return Db::name($this->table)->where($where)->field($filed)->select();
    }

}